<?php
	session_start();
    if($_SESSION['uid']==""||$_SESSION['level']!=3){
		header("Location: ./exit.php");
		exit();
	}
	include('/php/tool/submitValidate.php');
	include('/php/tool/pdo.php');
	include('/php/bll/DormCenterBLL.php');
	include('/php/class/dorm-center.class.php');

	(int)$status = isset($_GET['status']) ? (int)$_GET['status'] : 0;
	(int)$major = isset($_GET['major']) ? (int)$_GET['major'] : 0;
	(int)$grade = isset($_GET['grade']) ? (int)$_GET['grade'] : 0;
	(int)$page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
	(int)$pageSize = isset($_GET['pageSize']) ? (int)$_GET['pageSize'] : 20;
	$search = isset($_GET['search']) ? $_GET['search'] : '';

	$dormCenterBLL=new DormCenterBLL();
	if($dormCenterBLL->inputValidateView($status,$major,$grade,$page,$pageSize)){
		header("Location: ./instructor-major-allocating.php");
	}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5shiv.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<script src="./scripts/crypto-js/core.js"></script>
<script src="./scripts/crypto-js/md5.js"></script>
<title>辅导员管理</title>
</head>
<body>
<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 管理员管理 
	<span class="c-gray en">&gt;</span> 辅导员管理 
	<a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
		<i class="Hui-iconfont">&#xe68f;</i>
	</a>
</nav>
<div class="page-container">
	<div class="cl pd-5 mybg-2 bk-gray"> 
		<span class="l"> 
			<a href="javascript:;" onclick="deleteInstructorMajorCheckbox()" class="btn btn-danger radius">
				<i class="Hui-iconfont">&#xe6e2;</i> 批量移除权限
			</a> 
		</span> 
		<span class="r">
			<button onclick="removeIframe()" class="btn btn-primary radius">关闭选项卡</button>
		</span>
	</div>
	<div class="mt-10">
		<form action="./php/dorm-center-instructor.php" method="post" class="form-horizontal mybg-2 bk-gray pt-5 pb-5">
			<div class="row cl mb-5">
				<label class="form-label col-xs-1" style="width:80px;margin:0;padding:0;line-height:31px;">状态：</label>
				<div class="formControls col-xs-8 col-sm-2">
					<select id="status_select" name="status_select" class="select" size="1" style="height:31px">
					<option value="0" <?php echo $status==0?'selected=""':''?>>所有</option>
					<option value="1" <?php echo $status==1?'selected=""':''?>>已分配</option>
					<option value="2" <?php echo $status==2?'selected=""':''?>>未分配</option>
					</select>
				</div>
				<label class="form-label col-xs-1" style="width:120px;margin:0;padding:0;line-height:31px;">专业：</label>
				<div class="formControls col-xs-8 col-sm-3">
					<select id="major_select" name="major_select" class="select" size="1" style="height:31px">
					<option value="0">所有</option>
						<?php
							//$majorString='';
							//获取专业列表
							$majorList=$dormCenterBLL->getMajorList();
							foreach($majorList as $myMajor){
								echo '<option value="'.$myMajor['major_id'].'">'.$myMajor['major_name'].'</option>';
							}
							//
						?>
					</select>
				</div>
			</div>
			<div class="row cl mb-5">
				<label class="form-label col-xs-1" style="width:80px;margin:0;padding:0;line-height:31px;">年级：</label>
				<div class="formControls col-xs-8 col-sm-2">
					<select id="grade_select" name="role_select" class="select" size="1" style="height:31px">
					<option value="0">所有</option>
						<?php
							$gradeList=$dormCenterBLL->getGradeList();
							foreach($gradeList as $myGrade){
								echo '<option value="'.$myGrade['grade'].'">'.$myGrade['grade'].'</option>';
							}
							//$str='<option value="2">2</option>';
						?>
					</select>
				</div>
				<label class="form-label col-xs-4" style="width:120px;margin:0;padding:0;line-height:31px;">姓名或账号：</label>
				<div class="formControls col-xs-8 col-sm-3">
					<input  id="search" type="text" class="input-text" style="width:100%"  value="<?PHP echo $search;?>" placeholder="">
					<label id="search-error" class="error valid" for="search" style="display:none;">这是必填字段</label>
				</div>
				<button id="btn-search" onclick="searchInstructor()" class="btn btn-success" type="button"><i class="Hui-iconfont">&#xe665;</i> 查找</button>
			</div>
		</form>
	</div>
	<table class="table table-border table-bordered table-hover table-bg mt-10">
		<thead>
			<tr>
				<th scope="col" colspan="7">用户管理</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" value="" name=""></th>
				<th width="150">账号</th>
				<th width="180">姓名</th>
				<th while="180">年级</th>
				<th width="230">专业</th>
				<th width="180">手机号</th>
				<th width="70">操作</th>
			</tr>
		</thead>
		<tbody id="">
			<?php
				//用户列表
				$userList=$dormCenterBLL->getInstructorList($status,$major,$grade,$page,$pageSize,$search);
				foreach($userList as $user){
					$infoList=$dormCenterBLL->getInstructorInfoList($user['uid'],$grade,$major);
					$infoListCount=count($infoList);
					if($infoListCount>0){
						for($i=0;$i<$infoListCount;$i++){
							echo '<tr class="text-c">
							<td><input type="checkbox" value="'.$infoList[$i]['id'].'" name="instructor_checkbox"></td>
							<td class="uid">'.$user['uid'].'</td>
							<td class="name">'.$user['name'].'</td>
							<td class="grade">'.$infoList[$i]['grade'].'</td>
							<td class="major">'.$infoList[$i]['major'].'</td>
							<td style="display:none" class="major_id">'.$infoList[$i]['major_id'].'</td>
							<td class="phone">'.$user['phone'].'</td>
							<td class="f-14"><a title="添加" href="javascript:;" onclick="instructor_major_add(this,'.$user['uid'].')" style="text-decoration:none">
							<i class="Hui-iconfont">&#xe600;</i></a>
							<a title="编辑" href="javascript:;" onclick="instructor_major_edit(this,'.$infoList[$i]['id'].')" style="text-decoration:none">
							<i class="Hui-iconfont">&#xe6df;</i></a>
							<a title="删除" href="javascript:;" onclick="deleteInstructorMajor(this,'.$infoList[$i]['id'].')" class="ml-5" style="text-decoration:none">
							<i class="Hui-iconfont">&#xe6e2;</i></a></td></tr>';//&#xe600;
						}
					}else{
						echo '<tr class="text-c">
							<td><input type="checkbox" value="" name="instructor_checkbox"></td>
							<td class="uid">'.$user['uid'].'</td>
							<td class="name">'.$user['name'].'</td>
							<td class="grade"></td>
							<td class="major"></td>
							<td class="phone">'.$user['phone'].'</td>
							<td class="f-14"><a title="添加" href="javascript:;" onclick="instructor_major_add(this,'.$user['uid'].')" style="text-decoration:none">
							<i class="Hui-iconfont">&#xe600;</i></a>
							<a title="编辑" href="javascript:;" onclick="instructor_major_edit(this,'.$user['uid'].')" style="text-decoration:none">
							<i class="Hui-iconfont">&#xe6df;</i></a>
							<a title="删除" href="javascript:;" onclick="deleteInstructorMajor(this,'.$user['uid'].')" class="ml-5" style="text-decoration:none">
							<i class="Hui-iconfont">&#xe6e2;</i></a></td></tr>';//&#xe600;
					}
				}
			?>
			<!--<tr class="text-c">
				<td><input type="checkbox" value="" name=""></td>
				<td>1</td>
				<td>超级管理员</td>
				<td></td>
				<td>1</td>
				<td>拥有至高无上的权利</td>
				<td class="f-14"><a title="编辑" href="javascript:;" onclick="admin_role_edit('角色编辑','admin-role-add.html','1')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="admin_role_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
			</tr>-->
		</tbody>
	</table>
	<div class="modal-footer">
		<a class="btn" href="<?php echo './instructor-major-allocating.php?status='.$status.'&major='.$major.'&grade='.$grade.'&page='.($page-1>0?$page-1:0).'&pageSize='.$pageSize.'&search='.$search; ?>">上一页</a>
			<span><select  id="instructor_page" name="page" class="btn">
				<?php
					//$option='<option value="0">1</option>';
					$pageMax=$dormCenterBLL->getInstructorListPage((int)$status,(int)$major,(int)$grade,(int)$pageSize,$search);
					if($pageMax>0){
						for($i=0;$i<$pageMax;$i++){
							if($i==$page){//selected=""
								echo '<option value="'.$i.'" selected="selected">'.($i+1).'</option>';
							}else{
								echo '<option value="'.$i.'" ">'.($i+1).'</option>';
							}
						}
					}else{
						echo '<option value="0">1</option>';
					}
				?>
			</select>
		</span>
		<a class="btn" href="<?php echo './instructor-major-allocating.php?status='.$status.'&major='.$major.'&grade='.$grade.'&page='.($page+1<$pageMax?$page+1:$page).'&pageSize='.$pageSize.'&search='.$search; ?>">下一页</a>
	</div>
</div>
<!--遮罩层,编辑用户信息-->
	<div id="modal-edit-instructor" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width:80%;">
			<div class="modal-content radius">
				<div class="modal-header">
					<h3 class="modal-title">编辑管理信息</h3>
					<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
				</div>
				<div class="modal-body">
					<div class="mt-10">
						<div class="form-horizontal mybg-2 bk-gray pt-5 pb-5" id="form-article-add">
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">账号：</label>
								<div class="formControls col-xs-8 col-sm-4">
									<lable id="edit-uid" class="input-text col-xs-8 col-sm-4"></lable>
									<input style="display:none" type="checkbox" value="" id="edit_checkbox">
								</div>
							</div>
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">姓名：</label>
								<div class="formControls col-xs-8 col-sm-4">
									<lable id="edit-name" class="input-text col-xs-8 col-sm-4"></lable>
								</div>
							</div>
							<div class="row cl">
								<label class="form-label col-xs-4 col-sm-2">专业与年级：</label>
								<div class="formControls col-xs-8 col-sm-9">
									<table class="table table-border table-bordered table-bg">
										<thead>
											<tr class="text-c">
												<th width="50%">专业</th>
												<th width="50%">年级</th>
											</tr>
										</thead>
										<tbody id="update-instructor">
											<tr>
												<td>
													<select id="edit_major_select" name="edit_major_select" class="select" size="1" style="height:31px">
														<?php
															foreach($majorList as $major){
																echo '<option value="'.$major['major_id'].'">'.$major['major_name'].'</option>';
															}
														?>
													</select>
												</td>
												<td>
													<select id="edit_grade_select" name="edit_grade_select" class="select" size="1" style="height:31px">
														<?php
															date_default_timezone_set("PRC");
															$grade_min=(int)(date('Y'))-8;
															$grade_now=(int)(date('Y'));
															for($i=$grade_min;$i<$grade_now;$i++){
																echo '<option value="'.$i.'">'.$i.'</option>';
															}
															echo '<option value="'.$i.'" selected="">'.$i.'</option>'
														?>
													</select>
												</td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<div class="modal-footer mybg-2">
							<button id="edit-user" onclick="editInstructorMajor()" class="btn btn-primary radius">确定</button>
							<button class="btn btn-default radius" data-dismiss="modal" aria-hidden="true">取消</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!--遮罩层,添加辅导员管理信息-->
	<div id="modal-add-instructor" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog" style="width:80%;">
			<div class="modal-content radius">
				<div class="modal-header">
					<h3 class="modal-title">添加管理信息</h3>
					<a class="close" data-dismiss="modal" aria-hidden="true" href="javascript:void();">×</a>
				</div>
				<div class="modal-body">
					<div class="mt-10">
						<div class="form-horizontal mybg-2 bk-gray pt-5 pb-5" id="form-article-add">
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">账号：</label>
								<div class="formControls col-xs-8 col-sm-4">
									<lable id="add-uid" class="input-text col-xs-8 col-sm-4"></lable>
								</div>
								
							</div>
							<div class="row cl mb-5">
								<label class="form-label col-xs-4 col-sm-2">姓名：</label>
								<div class="formControls col-xs-8 col-sm-4">
									<lable id="add-name" class="input-text col-xs-8 col-sm-4"></lable>
								</div>
							</div>
							<div class="row cl">
								<label class="form-label col-xs-4 col-sm-2">专业与年级：</label>
								<div class="formControls col-xs-8 col-sm-9">
									<table class="table table-border table-bordered table-bg">
										<thead>
											<tr class="text-c">
												<th width="50%">专业</th>
												<th width="50%">年级</th>
											</tr>
										</thead>
										<tbody id="add-instructor">
											<tr>
												<td>
													<select id="add_major_select" name="add_major_select" class="select" size="1" style="height:31px">
															<?php
																foreach($majorList as $major){
																	echo '<option value="'.$major['major_id'].'">'.$major['major_name'].'</option>';
																}
															?>
													</select>
												</td>
												<td>
													<select id="add_grade_select" name="add_grade_select" class="select" size="1" style="height:31px">
														<?php
															$grade_min=date('Y')-4;
															$grade_now=date('Y');
															for($i=$grade_min;$i<$grade_now;$i++){
																echo '<option value="'.$i.'">'.$i.'</option>';
															}
															echo '<option value="'.$i.'" selected="">'.$i.'</option>'
														?>
													</select>
												</td>
											</tr>
											<?php

											?>
										</tbody>
									</table>
								</div>
							</div>
						</div>
						<div class="modal-footer mybg-2">
							<button id="add-user" onclick="addInstructorMajor()" class="btn btn-primary radius">添加</button>
							<button class="btn btn-default radius" data-dismiss="modal" aria-hidden="true">取消</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</body>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="scripts/instructor-major-allocating.jquery.js"></script>
</body>
</html>